package com.chenxinzhi.codetools

import com.chenxinzhi.codetools.message.message
import com.chenxinzhi.codetools.ui.CodeGen
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.NlsContexts.TabTitle
import com.intellij.openapi.wm.ToolWindow
import com.intellij.openapi.wm.ToolWindowFactory
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.jetbrains.jewel.bridge.addComposeTab
import org.jetbrains.jewel.ui.component.Text
import javax.swing.JComponent

@Suppress("unused")
@ExperimentalCoroutinesApi
internal class ToolWindowFactory : ToolWindowFactory, DumbAware {
    override fun createToolWindowContent(project: Project, toolWindow: ToolWindow) {
        toolWindow.addComposeTab(message("code.generation")) {
            CodeGen(project)
        }
        toolWindow.addComposeTab(message("encoding.conversion")) {
            Text("TODO")
        }
        toolWindow.addComposeTab(message("music")) {
            Text("TODO")
        }
        toolWindow.addComposeTab(message("qr.code")) {
            Text("TODO")
        }

    }

    private fun ToolWindow.addSwingTab(component: JComponent, @TabTitle title: String) {
        val manager = contentManager
        val tabContent = manager.factory.createContent(component, title, true)
        tabContent.isCloseable = false
        manager.addContent(tabContent)
    }
}